/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 1

Using: Hw1Types.h

Description:
A simple linked list implementation. It has, in addition to a normal linked 
list, an item count, and pointers to both the anchor, and the last item.
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef LINKED_LIST_H
#define LINKED_LIST_H

#include "Hw1Types.h" // For BOOL



struct TListItemStruct
{
	void* Value;
	struct TListItemStruct* NextItem;
	struct TListItemStruct* PrevItem;
};
typedef struct TListItemStruct TListItem;
typedef TListItem* PListItem;

struct TListStruct
{
	PListItem Anchor;
	PListItem Last;
	int Count;
};
typedef struct TListStruct TList;
typedef TList* PList;


/* InitializeList()
 * -----------------------------------
 * Returns a newly allocated list														*/
PList InitializeList();

/* CreateValue(void* value)
 * -----------------------------------
 * Returns a new list item with value assigned to it									*/
PListItem CreateValue(void* value);

/* AddValue(PList list, void* value);
 * -----------------------------------
 * Creates a new list item, assigning value to it, and adds it 
 * to list (on the end of the list). Returns the added list item (if it was added)		*/
PListItem AddValue(PList list, void* value);

/* AddItem(PList list, PListItem item)
 * -----------------------------------
 * Adds item to list (on the end of the list) and returns the item (if it was added)	*/
PListItem AddItem(PList list, PListItem item);

/* InsertItemAfter(PList list, PListItem itemBefore, PListItem itemToInsert)
 * -------------------------------------------------------------------------
 * Inserts itemToInsert to list so it'll be the item after itemBefore      
 * Returns TRUE on success																*/
BOOL InsertItemAfter(PList list, PListItem itemBefore, PListItem itemToInsert);

/* InsertItemBefore(PList list, PListItem itemNext, PListItem itemToInsert)
 * -------------------------------------------------------------------------
 * Inserts itemToInsert to list so it'll be the item before itemNext      
 * Returns TRUE on success																*/
BOOL InsertItemBefore(PList list, PListItem itemNext, PListItem itemToInsert);

/* RemoveItem(PList list, PListItem item);
 * -------------------------------------------------------------------------
 * Removes item from list, and frees item (and its value!)
 * Returns TRUE on success																*/
BOOL RemoveItem(PList list, PListItem item);

/* GetNext(PListItem item)
 * -------------------------------------------------------------------------
 * Returns the next item in the list after item											*/
PListItem GetNext(PListItem item);

/* GetPrev(PListItem item)
 * -------------------------------------------------------------------------
 * Returns the previous item in the list before item									*/
PListItem GetPrev(PListItem item);

/* FreeList(PList list);
 * -------------------------------------------------------------------------
 * Frees list, freeing all its items													*/
BOOL FreeList(PList list);

#endif // LINKED_LIST_H